﻿Imports System.Data
Imports System.Data.Odbc

Module dataCargaDeuda
    Dim VectorDepartamento(16, 5) As String
    Sub datosDepCBCargaBlock()

        conectar()
        Dim dt2 As New DataTable

        cmd = New OdbcCommand("SELECT ID, Nombre FROM  tblock", con)
        dr = cmd.ExecuteReader
        'executing the command and assigning it to connection 

        dt2.Load(dr, LoadOption.OverwriteChanges)
        With frmCargaDeuda.cbBlock
            .DataSource = dt2
            .DisplayMember = dt2.Columns.Item(1).Caption
            .ValueMember = dt2.Columns.Item(0).Caption
        End With
        ' listaDepartamentos(frmDepartamento.cbSelBlock.SelectedValue)
        desconectar()

    End Sub



    Function listadoCargaDepartamento(ByVal IDBlock As Integer)
        Dim i As Integer
        Dim depa As String
        frmCargaDeuda.cbDepartamento.Items.Clear()
        conectar()

        cmd.Connection = con
        cmd.CommandText = "SELECT d.ID,d.IDBlock,d.NumeroActual,d.NumeroAnterior,p.Nombre,p.ApPaterno,p.ApMaterno "
        cmd.CommandText += "FROM tDepartamento d INNER JOIN tPersonas p ON p.ID=d.IDPropietario "
        cmd.CommandText += "WHERE p.IDTipoRelacion=1 AND d.IDBlock=" + IDBlock.ToString
        cmd.CommandType = CommandType.Text

        dr = cmd.ExecuteReader
        If dr.HasRows Then
            While dr.Read()
                VectorDepartamento(i, 0) = dr("ID").ToString
                VectorDepartamento(i, 1) = dr("IDBlock").ToString
                VectorDepartamento(i, 2) = dr("NumeroActual").ToString
                VectorDepartamento(i, 3) = dr("NumeroAnterior").ToString
                VectorDepartamento(i, 4) = dr("Nombre").ToString + " " + dr("ApPaterno").ToString + " " + dr("ApMaterno").ToString
                depa = Trim(dr("NumeroActual").ToString) & " EX " & Trim(dr("NumeroAnterior").ToString)
                frmCargaDeuda.cbDepartamento.Items.Add(Trim(depa))
                i += 1
                depa = ""
            End While
        End If
        dr.Close()
        desconectar()
        Return VectorDepartamento
    End Function


    Sub ModificarGastos(ByVal vID As Integer, ByVal valorIni As Integer, ByVal valorGc As Integer)
        Try

      
        conectar()

            cmd = New OdbcCommand("UPDATE tDepartamento set  SaldoIniDeudaArrastre='" & valorIni & "',SaldoIniDeudaGc='" & valorGc & "' WHERE  ID ='" & vID & "' ", con)
            If cmd.ExecuteNonQuery() Then
                frmCargaDeuda.lblMensaje.Visible = True

            Else
                MessageBox.Show(msjNoIngresar, msjTituloModal, MessageBoxButtons.OK, MessageBoxIcon.Error)
            End If



            desconectar()
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try

    End Sub

End Module
